//Code to determine sensor configuration

//Codes (Start/End)
#define strtpkt 0x01
#define endpkt  0x04

//Data Lengths
#define Uint8   0x0000
#define Uint16  0x0100
#define Uint32  0x0200
#define Strng   0x0300

//SENSOR CODES
#define ELYCRA  0x0000
#define THERM   0x0001
#define FORCE   0x0002
#define GPS     0x0003
#define ACCX    0x0004
#define ACCY    0x0005
#define ACCZ    0x0006
#define MMG     0x0007
#define PULSE   0x0008
#define FLEX    0x0009
//These have been defined like this so they can be combined with an OR function to give 2byte value showing sensor and corresponding data length
//Data is little endian, so sensor is defined in least significant byte

#define datalength  28 //Length of DataContent is 28

void setup()
{
  unsigned char SensorConfig[35]; //28 Bytes for sensors and data length + 2 for start/end packet + 2 for data length + 2 for checksum + 1 for message tupe
  
  unsigned short checksum=0;
  char i;
    
  SensorConfig[0]=strtpkt;
  SensorConfig[1]=0x20; //Data Config Message
    
  //Create Pointer to 3rd Byte in SensorConfig and create short (2byte) pointer, all values up to endpacket are shorts and pointer counts up to endpacket
  unsigned short* ConfigPoint=(unsigned short*)SensorConfig[2];
  ConfigPoint[0]=datalength;
  ConfigPoint[1]=ELYCRA|Uint16; //left
  ConfigPoint[2]=ELYCRA|Uint16; //right
  ConfigPoint[3]=FLEX|Uint16;   //left
  ConfigPoint[4]=FLEX|Uint16;   //right
  ConfigPoint[5]=FORCE|Uint16;  //left
  ConfigPoint[6]=FORCE|Uint16;  //right
  ConfigPoint[7]=MMG|Uint16;    //left
  ConfigPoint[8]=MMG|Uint16;    //right
  ConfigPoint[9]=ACCX|Uint16;
  ConfigPoint[10]=ACCY|Uint16;
  ConfigPoint[11]=ACCZ|Uint16;
  ConfigPoint[12]=PULSE|Uint16;
  ConfigPoint[13]=THERM|Uint16;
  ConfigPoint[14]=GPS|Strng;
  
  //Calculate checksum - don't have to worry about having odd number of bytes at the end because each value in data content is 2 bytes
  for (i=0; i<14; i++)
  {
    checksum=checksum^ConfigPoint[i];
  }
  
  ConfigPoint[15]=checksum;
  
  SensorConfig[34]=endpkt;
}

void loop()
{
}


